package com.wondersgroup.fjzlpt.org.controller.rest.fwb;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.quick.framework.util.ExcelOrWordUtils;
import com.quick.framework.util.QuickPrincipalUtils;
import com.wondersgroup.fjzlpt.org.util.ControllerCommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.quick.framework.boot.web.utils.RequestUtils;
import com.wondersgroup.fjzlpt.org.service.inter.fwb.FwbService;

@RestController
@RequestMapping("fwb")
public class FwbRestController {
	
	@Autowired
	private FwbService fwbService;

	@RequestMapping("/queryPage")
	public JSONObject queryPageYljgxx(HttpServletRequest request)
	{
		Map<String, String> map = RequestUtils.GetParameterMap(request);
		ControllerCommonUtil.pageFormat(map);
		map.put("YLJGID_this", QuickPrincipalUtils.getPtjgID(request)); //本机构的id
		return fwbService.queryPage(map);
	}
	
	@RequestMapping("/save")
	public JSONObject save(HttpServletRequest request)
	{
		Map<String, String> map = RequestUtils.GetParameterMap(request);
        map.put("JGLB", QuickPrincipalUtils.getJglbdm(request));
        map.put("XJJGID", QuickPrincipalUtils.getPtjgID(request));
		return fwbService.save(map);
	}
	
	@RequestMapping("/queryAll")
	public JSONArray queryAll(HttpServletRequest request)
	{
		Map<String, String> map = RequestUtils.GetParameterMap(request);
		return fwbService.queryAll(map);
	}
	
	@RequestMapping("/stop")
	public JSONObject stop(HttpServletRequest request)
	{
		Map<String, String> map = RequestUtils.GetParameterMap(request);
		return fwbService.stop(map);
	}
	
	@RequestMapping("/start")
	public JSONObject start(HttpServletRequest request)
	{
		Map<String, String> map = RequestUtils.GetParameterMap(request);
		return fwbService.start(map);
	}
	
	@RequestMapping("/export")
	public void export(HttpServletRequest request,HttpServletResponse response)
	{
		Map<String, String> map = RequestUtils.GetParameterMap(request);
		
		map.put("YLJGID", QuickPrincipalUtils.getPtjgID(request));
		
		JSONArray jsarry = fwbService.queryList(map);
		
		List<String> titleField = new ArrayList<String>();
		titleField.add("FWBID");
		titleField.add("FWBMC");
		titleField.add("YLJGMC");
		titleField.add("FY");
		titleField.add("FWBZT");
		titleField.add("CJSJ");
		ExcelOrWordUtils.downLoadExcelFile(jsarry, titleField, "服务包信息", request, response);
	}
	
}
